package com.stylefeng.guns.core.util;

import java.text.DecimalFormat;

/**
 * 格式化数字为千分位工具类
 */
public class FmtMicrometer {

    /**
     *
     * @param number 需要格式化的值
     * @param length 保留小数点后多少位
     * @return
     */
    public static String fmtMicrometer(Double number, int length, boolean isFormart){
        if(length >= 0){
            StringBuilder sb = null;
            if(length == 0){
                sb = new StringBuilder("###,##0");
            }else{
                sb = new StringBuilder("###,##0.");
            }
            for (int i = 0; i < length; i++) {
                sb.append("0");
            }

            DecimalFormat df = new DecimalFormat(sb.toString());
            if(isFormart){
                if(number >= 0){
                    return  df.format(number);
                }else{
                    return "("+df.format(number).substring(1)+")";
                }
            }else{
                return  df.format(number);
            }
        }
        return "-";
    }


    public static String fmtMicrometer(Double number){

            DecimalFormat df = new DecimalFormat();
            if(number >= 0){
                return  df.format(number);
            }else{
                return "("+df.format(number).substring(1)+")";
            }
    }

    public static void main(String [] args){
        DecimalFormat d1 =new DecimalFormat();
        System.out.println(d1.format(-12312323423423.123283123));
        System.out.println(d1.format(-12312323423423.123283123).substring(1));
    }

}
